package routes

import (
	v1 "biyesheji/api/v1"
	"biyesheji/middleware"
	"biyesheji/utils"

	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	// r := gin.Default()
	r := gin.New()
	r.Use(gin.Recovery()) // 自己new的情况下需要手动引入这个中间件处理错误，自动写入500
	r.Use(middleware.Cors())
	r.Use(middleware.Logger())

	// 公共接口
	public := r.Group("api/v1")
	{
		// 症状列表
		public.GET("sympthom", v1.GetAllSympthom)
		public.GET("sympthom/keyword", v1.GetKeyword)
		public.GET("sympthom/name", v1.GetSympthomName)
		public.GET("sympthom/morekeyword", v1.GetMoreKeyword)
		public.GET("sympthom/someinfo", v1.GetSomeInfo)
		// 用户模块
		public.POST("login", v1.Login)
	}
	// 需要token的接口
	token := r.Group("api/v1")
	token.Use(middleware.JwtToken())
	{
		// 用户模块
		token.POST("user/add", v1.AddUser)
		token.GET("user", v1.GetUsers)
		token.PUT("user/:id", v1.EditUser)
		token.DELETE("user/:id", v1.DeleteUser)
		token.GET("user/anyuser", v1.GetAnyUsers)
		// 症状模块
		token.PUT("sympthom/:id", v1.EditSympthom)
		token.GET("sympthom/like", v1.GetLikeSympthom)
		token.POST("sympthom/add", v1.AddSympthom)
	}

	r.Run(utils.HttpPort)
}
